<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - id:000977,sync:fuzzer2,src:001052.lcov_info_final - test/gmock-1.7.0/include/gmock/gmock-actions.h</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">test/gmock-1.7.0/include/gmock</a> - gmock-actions.h<span style="font-size: 80%;"> (source / <a href="gmock-actions.h.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">id:000977,sync:fuzzer2,src:001052.lcov_info_final</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">13</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2016-03-13 10:42:47</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">33</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : // Copyright 2007, Google Inc.</a>
<span class="lineNum">       2 </span>            : // All rights reserved.
<span class="lineNum">       3 </span>            : //
<span class="lineNum">       4 </span>            : // Redistribution and use in source and binary forms, with or without
<span class="lineNum">       5 </span>            : // modification, are permitted provided that the following conditions are
<span class="lineNum">       6 </span>            : // met:
<span class="lineNum">       7 </span>            : //
<span class="lineNum">       8 </span>            : //     * Redistributions of source code must retain the above copyright
<span class="lineNum">       9 </span>            : // notice, this list of conditions and the following disclaimer.
<span class="lineNum">      10 </span>            : //     * Redistributions in binary form must reproduce the above
<span class="lineNum">      11 </span>            : // copyright notice, this list of conditions and the following disclaimer
<span class="lineNum">      12 </span>            : // in the documentation and/or other materials provided with the
<span class="lineNum">      13 </span>            : // distribution.
<span class="lineNum">      14 </span>            : //     * Neither the name of Google Inc. nor the names of its
<span class="lineNum">      15 </span>            : // contributors may be used to endorse or promote products derived from
<span class="lineNum">      16 </span>            : // this software without specific prior written permission.
<span class="lineNum">      17 </span>            : //
<span class="lineNum">      18 </span>            : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
<span class="lineNum">      19 </span>            : // &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
<span class="lineNum">      20 </span>            : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
<span class="lineNum">      21 </span>            : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
<span class="lineNum">      22 </span>            : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
<span class="lineNum">      23 </span>            : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
<span class="lineNum">      24 </span>            : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<span class="lineNum">      25 </span>            : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
<span class="lineNum">      26 </span>            : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<span class="lineNum">      27 </span>            : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<span class="lineNum">      28 </span>            : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<span class="lineNum">      29 </span>            : //
<span class="lineNum">      30 </span>            : // Author: wan@google.com (Zhanyong Wan)
<span class="lineNum">      31 </span>            : 
<span class="lineNum">      32 </span>            : // Google Mock - a framework for writing C++ mock classes.
<span class="lineNum">      33 </span>            : //
<span class="lineNum">      34 </span>            : // This file implements some commonly used actions.
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span>            : #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
<span class="lineNum">      37 </span>            : #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span>            : #ifndef _WIN32_WCE
<span class="lineNum">      40 </span>            : # include &lt;errno.h&gt;
<span class="lineNum">      41 </span>            : #endif
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">      44 </span>            : #include &lt;string&gt;
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            : #include &quot;gmock/internal/gmock-internal-utils.h&quot;
<span class="lineNum">      47 </span>            : #include &quot;gmock/internal/gmock-port.h&quot;
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : namespace testing {
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span>            : // To implement an action Foo, define:
<span class="lineNum">      52 </span>            : //   1. a class FooAction that implements the ActionInterface interface, and
<span class="lineNum">      53 </span>            : //   2. a factory function that creates an Action object from a
<span class="lineNum">      54 </span>            : //      const FooAction*.
<span class="lineNum">      55 </span>            : //
<span class="lineNum">      56 </span>            : // The two-level delegation design follows that of Matcher, providing
<span class="lineNum">      57 </span>            : // consistency for extension developers.  It also eases ownership
<span class="lineNum">      58 </span>            : // management as Action objects can now be copied like plain values.
<span class="lineNum">      59 </span>            : 
<span class="lineNum">      60 </span>            : namespace internal {
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span>            : template &lt;typename F1, typename F2&gt;
<span class="lineNum">      63 </span>            : class ActionAdaptor;
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span>            : // BuiltInDefaultValue&lt;T&gt;::Get() returns the &quot;built-in&quot; default
<span class="lineNum">      66 </span>            : // value for type T, which is NULL when T is a pointer type, 0 when T
<span class="lineNum">      67 </span>            : // is a numeric type, false when T is bool, or &quot;&quot; when T is string or
<span class="lineNum">      68 </span>            : // std::string.  For any other type T, this value is undefined and the
<span class="lineNum">      69 </span>            : // function will abort the process.
<span class="lineNum">      70 </span>            : template &lt;typename T&gt;
<span class="lineNum">      71 </span>            : class BuiltInDefaultValue {
<span class="lineNum">      72 </span>            :  public:
<span class="lineNum">      73 </span>            :   // This function returns true iff type T has a built-in default value.
<span class="lineNum">      74 </span>            :   static bool Exists() { return false; }
<span class="lineNum">      75 </span>            :   static T Get() {
<span class="lineNum">      76 </span>            :     Assert(false, __FILE__, __LINE__,
<span class="lineNum">      77 </span>            :            &quot;Default action undefined for the function return type.&quot;);
<span class="lineNum">      78 </span>            :     return internal::Invalid&lt;T&gt;();
<span class="lineNum">      79 </span>            :     // The above statement will never be reached, but is required in
<span class="lineNum">      80 </span>            :     // order for this function to compile.
<span class="lineNum">      81 </span>            :   }
<span class="lineNum">      82 </span>            : };
<span class="lineNum">      83 </span>            : 
<span class="lineNum">      84 </span>            : // This partial specialization says that we use the same built-in
<span class="lineNum">      85 </span>            : // default value for T and const T.
<span class="lineNum">      86 </span>            : template &lt;typename T&gt;
<span class="lineNum">      87 </span>            : class BuiltInDefaultValue&lt;const T&gt; {
<span class="lineNum">      88 </span>            :  public:
<span class="lineNum">      89 </span>            :   static bool Exists() { return BuiltInDefaultValue&lt;T&gt;::Exists(); }
<span class="lineNum">      90 </span>            :   static T Get() { return BuiltInDefaultValue&lt;T&gt;::Get(); }
<span class="lineNum">      91 </span>            : };
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            : // This partial specialization defines the default values for pointer
<span class="lineNum">      94 </span>            : // types.
<span class="lineNum">      95 </span>            : template &lt;typename T&gt;
<span class="lineNum">      96 </span>            : class BuiltInDefaultValue&lt;T*&gt; {
<span class="lineNum">      97 </span>            :  public:
<span class="lineNum">      98 </span>            :   static bool Exists() { return true; }
<span class="lineNum">      99 </span>            :   static T* Get() { return NULL; }
<span class="lineNum">     100 </span>            : };
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span>            : // The following specializations define the default values for
<span class="lineNum">     103 </span>            : // specific types we care about.
<span class="lineNum">     104 </span>            : #define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
<span class="lineNum">     105 </span>            :   template &lt;&gt; \
<span class="lineNum">     106 </span>            :   class BuiltInDefaultValue&lt;type&gt; { \
<span class="lineNum">     107 </span>            :    public: \
<span class="lineNum">     108 </span>            :     static bool Exists() { return true; } \
<span class="lineNum">     109 </span>            :     static type Get() { return value; } \
<span class="lineNum">     110 </span>            :   }
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, );  // NOLINT
<span class="lineNum">     113 </span>            : #if GTEST_HAS_GLOBAL_STRING
<span class="lineNum">     114 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, &quot;&quot;);
<span class="lineNum">     115 </span>            : #endif  // GTEST_HAS_GLOBAL_STRING
<span class="lineNum">     116 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, &quot;&quot;);
<span class="lineNum">     117 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
<span class="lineNum">     118 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
<span class="lineNum">     119 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
<span class="lineNum">     120 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
<span class="lineNum">     121 </span>            : 
<span class="lineNum">     122 </span>            : // There's no need for a default action for signed wchar_t, as that
<span class="lineNum">     123 </span>            : // type is the same as wchar_t for gcc, and invalid for MSVC.
<span class="lineNum">     124 </span>            : //
<span class="lineNum">     125 </span>            : // There's also no need for a default action for unsigned wchar_t, as
<span class="lineNum">     126 </span>            : // that type is the same as unsigned int for gcc, and invalid for
<span class="lineNum">     127 </span>            : // MSVC.
<span class="lineNum">     128 </span>            : #if GMOCK_WCHAR_T_IS_NATIVE_
<span class="lineNum">     129 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U);  // NOLINT
<span class="lineNum">     130 </span>            : #endif
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U);  // NOLINT
<span class="lineNum">     133 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0);     // NOLINT
<span class="lineNum">     134 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
<span class="lineNum">     135 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
<span class="lineNum">     136 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL);  // NOLINT
<span class="lineNum">     137 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L);     // NOLINT
<span class="lineNum">     138 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
<span class="lineNum">     139 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
<span class="lineNum">     140 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
<span class="lineNum">     141 </span>            : GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
<span class="lineNum">     142 </span>            : 
<span class="lineNum">     143 </span>            : #undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            : }  // namespace internal
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span>            : // When an unexpected function call is encountered, Google Mock will
<span class="lineNum">     148 </span>            : // let it return a default value if the user has specified one for its
<span class="lineNum">     149 </span>            : // return type, or if the return type has a built-in default value;
<span class="lineNum">     150 </span>            : // otherwise Google Mock won't know what value to return and will have
<span class="lineNum">     151 </span>            : // to abort the process.
<span class="lineNum">     152 </span>            : //
<span class="lineNum">     153 </span>            : // The DefaultValue&lt;T&gt; class allows a user to specify the
<span class="lineNum">     154 </span>            : // default value for a type T that is both copyable and publicly
<span class="lineNum">     155 </span>            : // destructible (i.e. anything that can be used as a function return
<span class="lineNum">     156 </span>            : // type).  The usage is:
<span class="lineNum">     157 </span>            : //
<span class="lineNum">     158 </span>            : //   // Sets the default value for type T to be foo.
<span class="lineNum">     159 </span>            : //   DefaultValue&lt;T&gt;::Set(foo);
<span class="lineNum">     160 </span>            : template &lt;typename T&gt;
<span class="lineNum">     161 </span>            : class DefaultValue {
<span class="lineNum">     162 </span>            :  public:
<span class="lineNum">     163 </span>            :   // Sets the default value for type T; requires T to be
<span class="lineNum">     164 </span>            :   // copy-constructable and have a public destructor.
<span class="lineNum">     165 </span>            :   static void Set(T x) {
<span class="lineNum">     166 </span>            :     delete value_;
<span class="lineNum">     167 </span>            :     value_ = new T(x);
<span class="lineNum">     168 </span>            :   }
<span class="lineNum">     169 </span>            : 
<span class="lineNum">     170 </span>            :   // Unsets the default value for type T.
<span class="lineNum">     171 </span>            :   static void Clear() {
<span class="lineNum">     172 </span>            :     delete value_;
<span class="lineNum">     173 </span>            :     value_ = NULL;
<span class="lineNum">     174 </span>            :   }
<span class="lineNum">     175 </span>            : 
<span class="lineNum">     176 </span>            :   // Returns true iff the user has set the default value for type T.
<span class="lineNum">     177 </span>            :   static bool IsSet() { return value_ != NULL; }
<span class="lineNum">     178 </span>            : 
<span class="lineNum">     179 </span>            :   // Returns true if T has a default return value set by the user or there
<span class="lineNum">     180 </span>            :   // exists a built-in default value.
<span class="lineNum">     181 </span>            :   static bool Exists() {
<span class="lineNum">     182 </span>            :     return IsSet() || internal::BuiltInDefaultValue&lt;T&gt;::Exists();
<span class="lineNum">     183 </span>            :   }
<span class="lineNum">     184 </span>            : 
<span class="lineNum">     185 </span>            :   // Returns the default value for type T if the user has set one;
<span class="lineNum">     186 </span>            :   // otherwise returns the built-in default value if there is one;
<span class="lineNum">     187 </span>            :   // otherwise aborts the process.
<span class="lineNum">     188 </span>            :   static T Get() {
<span class="lineNum">     189 </span>            :     return value_ == NULL ?
<span class="lineNum">     190 </span>            :         internal::BuiltInDefaultValue&lt;T&gt;::Get() : *value_;
<span class="lineNum">     191 </span>            :   }
<span class="lineNum">     192 </span>            : 
<span class="lineNum">     193 </span>            :  private:
<span class="lineNum">     194 </span>            :   static const T* value_;
<span class="lineNum">     195 </span>            : };
<span class="lineNum">     196 </span>            : 
<span class="lineNum">     197 </span>            : // This partial specialization allows a user to set default values for
<span class="lineNum">     198 </span>            : // reference types.
<span class="lineNum">     199 </span>            : template &lt;typename T&gt;
<span class="lineNum">     200 </span>            : class DefaultValue&lt;T&amp;&gt; {
<span class="lineNum">     201 </span>            :  public:
<span class="lineNum">     202 </span>            :   // Sets the default value for type T&amp;.
<span class="lineNum">     203 </span>            :   static void Set(T&amp; x) {  // NOLINT
<span class="lineNum">     204 </span>            :     address_ = &amp;x;
<span class="lineNum">     205 </span>            :   }
<span class="lineNum">     206 </span>            : 
<span class="lineNum">     207 </span>            :   // Unsets the default value for type T&amp;.
<span class="lineNum">     208 </span>            :   static void Clear() {
<span class="lineNum">     209 </span>            :     address_ = NULL;
<span class="lineNum">     210 </span>            :   }
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span>            :   // Returns true iff the user has set the default value for type T&amp;.
<span class="lineNum">     213 </span>            :   static bool IsSet() { return address_ != NULL; }
<span class="lineNum">     214 </span>            : 
<span class="lineNum">     215 </span>            :   // Returns true if T has a default return value set by the user or there
<span class="lineNum">     216 </span>            :   // exists a built-in default value.
<span class="lineNum">     217 </span>            :   static bool Exists() {
<span class="lineNum">     218 </span>            :     return IsSet() || internal::BuiltInDefaultValue&lt;T&amp;&gt;::Exists();
<span class="lineNum">     219 </span>            :   }
<span class="lineNum">     220 </span>            : 
<span class="lineNum">     221 </span>            :   // Returns the default value for type T&amp; if the user has set one;
<span class="lineNum">     222 </span>            :   // otherwise returns the built-in default value if there is one;
<span class="lineNum">     223 </span>            :   // otherwise aborts the process.
<span class="lineNum">     224 </span>            :   static T&amp; Get() {
<span class="lineNum">     225 </span>            :     return address_ == NULL ?
<span class="lineNum">     226 </span>            :         internal::BuiltInDefaultValue&lt;T&amp;&gt;::Get() : *address_;
<span class="lineNum">     227 </span>            :   }
<span class="lineNum">     228 </span>            : 
<span class="lineNum">     229 </span>            :  private:
<span class="lineNum">     230 </span>            :   static T* address_;
<span class="lineNum">     231 </span>            : };
<span class="lineNum">     232 </span>            : 
<span class="lineNum">     233 </span>            : // This specialization allows DefaultValue&lt;void&gt;::Get() to
<span class="lineNum">     234 </span>            : // compile.
<span class="lineNum">     235 </span>            : template &lt;&gt;
<a name="236"><span class="lineNum">     236 </span>            : class DefaultValue&lt;void&gt; {</a>
<a name="237"><span class="lineNum">     237 </span>            :  public:</a>
<span class="lineNum">     238 </span><span class="lineNoCov">          0 :   static bool Exists() { return true; }</span>
<span class="lineNum">     239 </span><span class="lineNoCov">          0 :   static void Get() {}</span>
<span class="lineNum">     240 </span>            : };
<span class="lineNum">     241 </span>            : 
<span class="lineNum">     242 </span>            : // Points to the user-set default value for type T.
<span class="lineNum">     243 </span>            : template &lt;typename T&gt;
<span class="lineNum">     244 </span>            : const T* DefaultValue&lt;T&gt;::value_ = NULL;
<span class="lineNum">     245 </span>            : 
<span class="lineNum">     246 </span>            : // Points to the user-set default value for type T&amp;.
<span class="lineNum">     247 </span>            : template &lt;typename T&gt;
<span class="lineNum">     248 </span>            : T* DefaultValue&lt;T&amp;&gt;::address_ = NULL;
<span class="lineNum">     249 </span>            : 
<span class="lineNum">     250 </span>            : // Implement this interface to define an action for function type F.
<span class="lineNum">     251 </span>            : template &lt;typename F&gt;
<span class="lineNum">     252 </span>            : class ActionInterface {
<span class="lineNum">     253 </span>            :  public:
<span class="lineNum">     254 </span>            :   typedef typename internal::Function&lt;F&gt;::Result Result;
<span class="lineNum">     255 </span>            :   typedef typename internal::Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span>            :   ActionInterface() {}
<span class="lineNum">     258 </span>            :   virtual ~ActionInterface() {}
<span class="lineNum">     259 </span>            : 
<span class="lineNum">     260 </span>            :   // Performs the action.  This method is not const, as in general an
<span class="lineNum">     261 </span>            :   // action can have side effects and be stateful.  For example, a
<span class="lineNum">     262 </span>            :   // get-the-next-element-from-the-collection action will need to
<span class="lineNum">     263 </span>            :   // remember the current element.
<span class="lineNum">     264 </span>            :   virtual Result Perform(const ArgumentTuple&amp; args) = 0;
<span class="lineNum">     265 </span>            : 
<span class="lineNum">     266 </span>            :  private:
<span class="lineNum">     267 </span>            :   GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
<span class="lineNum">     268 </span>            : };
<span class="lineNum">     269 </span>            : 
<span class="lineNum">     270 </span>            : // An Action&lt;F&gt; is a copyable and IMMUTABLE (except by assignment)
<span class="lineNum">     271 </span>            : // object that represents an action to be taken when a mock function
<span class="lineNum">     272 </span>            : // of type F is called.  The implementation of Action&lt;T&gt; is just a
<span class="lineNum">     273 </span>            : // linked_ptr to const ActionInterface&lt;T&gt;, so copying is fairly cheap.
<span class="lineNum">     274 </span>            : // Don't inherit from Action!
<span class="lineNum">     275 </span>            : //
<span class="lineNum">     276 </span>            : // You can view an object implementing ActionInterface&lt;F&gt; as a
<span class="lineNum">     277 </span>            : // concrete action (including its current state), and an Action&lt;F&gt;
<a name="278"><span class="lineNum">     278 </span>            : // object as a handle to it.</a>
<span class="lineNum">     279 </span>            : template &lt;typename F&gt;
<span class="lineNum">     280 </span><span class="lineNoCov">          0 : class Action {</span>
<span class="lineNum">     281 </span>            :  public:
<span class="lineNum">     282 </span>            :   typedef typename internal::Function&lt;F&gt;::Result Result;
<span class="lineNum">     283 </span>            :   typedef typename internal::Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     284 </span>            : 
<span class="lineNum">     285 </span>            :   // Constructs a null Action.  Needed for storing Action objects in
<span class="lineNum">     286 </span>            :   // STL containers.
<span class="lineNum">     287 </span>            :   Action() : impl_(NULL) {}
<span class="lineNum">     288 </span>            : 
<a name="289"><span class="lineNum">     289 </span>            :   // Constructs an Action from its implementation.  A NULL impl is</a>
<span class="lineNum">     290 </span>            :   // used to represent the &quot;do-default&quot; action.
<span class="lineNum">     291 </span><span class="lineNoCov">          0 :   explicit Action(ActionInterface&lt;F&gt;* impl) : impl_(impl) {}</span>
<a name="292"><span class="lineNum">     292 </span>            : </a>
<span class="lineNum">     293 </span>            :   // Copy constructor.
<span class="lineNum">     294 </span><span class="lineNoCov">          0 :   Action(const Action&amp; action) : impl_(action.impl_) {}</span>
<span class="lineNum">     295 </span>            : 
<span class="lineNum">     296 </span>            :   // This constructor allows us to turn an Action&lt;Func&gt; object into an
<span class="lineNum">     297 </span>            :   // Action&lt;F&gt;, as long as F's arguments can be implicitly converted
<span class="lineNum">     298 </span>            :   // to Func's and Func's return type can be implicitly converted to
<span class="lineNum">     299 </span>            :   // F's.
<span class="lineNum">     300 </span>            :   template &lt;typename Func&gt;
<span class="lineNum">     301 </span>            :   explicit Action(const Action&lt;Func&gt;&amp; action);
<a name="302"><span class="lineNum">     302 </span>            : </a>
<span class="lineNum">     303 </span>            :   // Returns true iff this is the DoDefault() action.
<span class="lineNum">     304 </span><span class="lineNoCov">          0 :   bool IsDoDefault() const { return impl_.get() == NULL; }</span>
<span class="lineNum">     305 </span>            : 
<span class="lineNum">     306 </span>            :   // Performs the action.  Note that this method is const even though
<span class="lineNum">     307 </span>            :   // the corresponding method in ActionInterface is not.  The reason
<span class="lineNum">     308 </span>            :   // is that a const Action&lt;F&gt; means that it cannot be re-bound to
<span class="lineNum">     309 </span>            :   // another concrete action, not that the concrete action it binds to
<a name="310"><span class="lineNum">     310 </span>            :   // cannot change state.  (Think of the difference between a const</a>
<span class="lineNum">     311 </span>            :   // pointer and a pointer to const.)
<span class="lineNum">     312 </span><span class="lineNoCov">          0 :   Result Perform(const ArgumentTuple&amp; args) const {</span>
<span class="lineNum">     313 </span><span class="lineNoCov">          0 :     internal::Assert(</span>
<span class="lineNum">     314 </span><span class="lineNoCov">          0 :         !IsDoDefault(), __FILE__, __LINE__,</span>
<span class="lineNum">     315 </span>            :         &quot;You are using DoDefault() inside a composite action like &quot;
<span class="lineNum">     316 </span>            :         &quot;DoAll() or WithArgs().  This is not supported for technical &quot;
<span class="lineNum">     317 </span>            :         &quot;reasons.  Please instead spell out the default action, or &quot;
<span class="lineNum">     318 </span>            :         &quot;assign the default action to an Action variable and use &quot;
<span class="lineNum">     319 </span>            :         &quot;the variable in various places.&quot;);
<span class="lineNum">     320 </span><span class="lineNoCov">          0 :     return impl_-&gt;Perform(args);</span>
<span class="lineNum">     321 </span>            :   }
<span class="lineNum">     322 </span>            : 
<span class="lineNum">     323 </span>            :  private:
<span class="lineNum">     324 </span>            :   template &lt;typename F1, typename F2&gt;
<span class="lineNum">     325 </span>            :   friend class internal::ActionAdaptor;
<span class="lineNum">     326 </span>            : 
<span class="lineNum">     327 </span>            :   internal::linked_ptr&lt;ActionInterface&lt;F&gt; &gt; impl_;
<span class="lineNum">     328 </span>            : };
<span class="lineNum">     329 </span>            : 
<span class="lineNum">     330 </span>            : // The PolymorphicAction class template makes it easy to implement a
<span class="lineNum">     331 </span>            : // polymorphic action (i.e. an action that can be used in mock
<span class="lineNum">     332 </span>            : // functions of than one type, e.g. Return()).
<span class="lineNum">     333 </span>            : //
<span class="lineNum">     334 </span>            : // To define a polymorphic action, a user first provides a COPYABLE
<span class="lineNum">     335 </span>            : // implementation class that has a Perform() method template:
<span class="lineNum">     336 </span>            : //
<span class="lineNum">     337 </span>            : //   class FooAction {
<span class="lineNum">     338 </span>            : //    public:
<span class="lineNum">     339 </span>            : //     template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     340 </span>            : //     Result Perform(const ArgumentTuple&amp; args) const {
<span class="lineNum">     341 </span>            : //       // Processes the arguments and returns a result, using
<span class="lineNum">     342 </span>            : //       // tr1::get&lt;N&gt;(args) to get the N-th (0-based) argument in the tuple.
<span class="lineNum">     343 </span>            : //     }
<span class="lineNum">     344 </span>            : //     ...
<span class="lineNum">     345 </span>            : //   };
<span class="lineNum">     346 </span>            : //
<span class="lineNum">     347 </span>            : // Then the user creates the polymorphic action using
<span class="lineNum">     348 </span>            : // MakePolymorphicAction(object) where object has type FooAction.  See
<span class="lineNum">     349 </span>            : // the definition of Return(void) and SetArgumentPointee&lt;N&gt;(value) for
<span class="lineNum">     350 </span>            : // complete examples.
<span class="lineNum">     351 </span>            : template &lt;typename Impl&gt;
<span class="lineNum">     352 </span>            : class PolymorphicAction {
<span class="lineNum">     353 </span>            :  public:
<span class="lineNum">     354 </span>            :   explicit PolymorphicAction(const Impl&amp; impl) : impl_(impl) {}
<span class="lineNum">     355 </span>            : 
<span class="lineNum">     356 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     357 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     358 </span>            :     return Action&lt;F&gt;(new MonomorphicImpl&lt;F&gt;(impl_));
<span class="lineNum">     359 </span>            :   }
<span class="lineNum">     360 </span>            : 
<span class="lineNum">     361 </span>            :  private:
<span class="lineNum">     362 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     363 </span>            :   class MonomorphicImpl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     364 </span>            :    public:
<span class="lineNum">     365 </span>            :     typedef typename internal::Function&lt;F&gt;::Result Result;
<span class="lineNum">     366 </span>            :     typedef typename internal::Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     367 </span>            : 
<span class="lineNum">     368 </span>            :     explicit MonomorphicImpl(const Impl&amp; impl) : impl_(impl) {}
<span class="lineNum">     369 </span>            : 
<span class="lineNum">     370 </span>            :     virtual Result Perform(const ArgumentTuple&amp; args) {
<span class="lineNum">     371 </span>            :       return impl_.template Perform&lt;Result&gt;(args);
<span class="lineNum">     372 </span>            :     }
<span class="lineNum">     373 </span>            : 
<span class="lineNum">     374 </span>            :    private:
<span class="lineNum">     375 </span>            :     Impl impl_;
<span class="lineNum">     376 </span>            : 
<span class="lineNum">     377 </span>            :     GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
<span class="lineNum">     378 </span>            :   };
<span class="lineNum">     379 </span>            : 
<span class="lineNum">     380 </span>            :   Impl impl_;
<span class="lineNum">     381 </span>            : 
<span class="lineNum">     382 </span>            :   GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
<span class="lineNum">     383 </span>            : };
<span class="lineNum">     384 </span>            : 
<span class="lineNum">     385 </span>            : // Creates an Action from its implementation and returns it.  The
<span class="lineNum">     386 </span>            : // created Action object owns the implementation.
<span class="lineNum">     387 </span>            : template &lt;typename F&gt;
<span class="lineNum">     388 </span>            : Action&lt;F&gt; MakeAction(ActionInterface&lt;F&gt;* impl) {
<span class="lineNum">     389 </span>            :   return Action&lt;F&gt;(impl);
<span class="lineNum">     390 </span>            : }
<span class="lineNum">     391 </span>            : 
<span class="lineNum">     392 </span>            : // Creates a polymorphic action from its implementation.  This is
<span class="lineNum">     393 </span>            : // easier to use than the PolymorphicAction&lt;Impl&gt; constructor as it
<span class="lineNum">     394 </span>            : // doesn't require you to explicitly write the template argument, e.g.
<span class="lineNum">     395 </span>            : //
<span class="lineNum">     396 </span>            : //   MakePolymorphicAction(foo);
<span class="lineNum">     397 </span>            : // vs
<span class="lineNum">     398 </span>            : //   PolymorphicAction&lt;TypeOfFoo&gt;(foo);
<span class="lineNum">     399 </span>            : template &lt;typename Impl&gt;
<span class="lineNum">     400 </span>            : inline PolymorphicAction&lt;Impl&gt; MakePolymorphicAction(const Impl&amp; impl) {
<span class="lineNum">     401 </span>            :   return PolymorphicAction&lt;Impl&gt;(impl);
<span class="lineNum">     402 </span>            : }
<span class="lineNum">     403 </span>            : 
<span class="lineNum">     404 </span>            : namespace internal {
<span class="lineNum">     405 </span>            : 
<span class="lineNum">     406 </span>            : // Allows an Action&lt;F2&gt; object to pose as an Action&lt;F1&gt;, as long as F2
<span class="lineNum">     407 </span>            : // and F1 are compatible.
<span class="lineNum">     408 </span>            : template &lt;typename F1, typename F2&gt;
<span class="lineNum">     409 </span>            : class ActionAdaptor : public ActionInterface&lt;F1&gt; {
<span class="lineNum">     410 </span>            :  public:
<span class="lineNum">     411 </span>            :   typedef typename internal::Function&lt;F1&gt;::Result Result;
<span class="lineNum">     412 </span>            :   typedef typename internal::Function&lt;F1&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     413 </span>            : 
<span class="lineNum">     414 </span>            :   explicit ActionAdaptor(const Action&lt;F2&gt;&amp; from) : impl_(from.impl_) {}
<span class="lineNum">     415 </span>            : 
<span class="lineNum">     416 </span>            :   virtual Result Perform(const ArgumentTuple&amp; args) {
<span class="lineNum">     417 </span>            :     return impl_-&gt;Perform(args);
<span class="lineNum">     418 </span>            :   }
<span class="lineNum">     419 </span>            : 
<span class="lineNum">     420 </span>            :  private:
<span class="lineNum">     421 </span>            :   const internal::linked_ptr&lt;ActionInterface&lt;F2&gt; &gt; impl_;
<span class="lineNum">     422 </span>            : 
<span class="lineNum">     423 </span>            :   GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
<span class="lineNum">     424 </span>            : };
<span class="lineNum">     425 </span>            : 
<span class="lineNum">     426 </span>            : // Implements the polymorphic Return(x) action, which can be used in
<span class="lineNum">     427 </span>            : // any function that returns the type of x, regardless of the argument
<span class="lineNum">     428 </span>            : // types.
<span class="lineNum">     429 </span>            : //
<span class="lineNum">     430 </span>            : // Note: The value passed into Return must be converted into
<span class="lineNum">     431 </span>            : // Function&lt;F&gt;::Result when this action is cast to Action&lt;F&gt; rather than
<span class="lineNum">     432 </span>            : // when that action is performed. This is important in scenarios like
<span class="lineNum">     433 </span>            : //
<span class="lineNum">     434 </span>            : // MOCK_METHOD1(Method, T(U));
<span class="lineNum">     435 </span>            : // ...
<span class="lineNum">     436 </span>            : // {
<span class="lineNum">     437 </span>            : //   Foo foo;
<span class="lineNum">     438 </span>            : //   X x(&amp;foo);
<span class="lineNum">     439 </span>            : //   EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
<span class="lineNum">     440 </span>            : // }
<span class="lineNum">     441 </span>            : //
<span class="lineNum">     442 </span>            : // In the example above the variable x holds reference to foo which leaves
<span class="lineNum">     443 </span>            : // scope and gets destroyed.  If copying X just copies a reference to foo,
<span class="lineNum">     444 </span>            : // that copy will be left with a hanging reference.  If conversion to T
<span class="lineNum">     445 </span>            : // makes a copy of foo, the above code is safe. To support that scenario, we
<span class="lineNum">     446 </span>            : // need to make sure that the type conversion happens inside the EXPECT_CALL
<span class="lineNum">     447 </span>            : // statement, and conversion of the result of Return to Action&lt;T(U)&gt; is a
<span class="lineNum">     448 </span>            : // good place for that.
<span class="lineNum">     449 </span>            : //
<span class="lineNum">     450 </span>            : template &lt;typename R&gt;
<span class="lineNum">     451 </span>            : class ReturnAction {
<span class="lineNum">     452 </span>            :  public:
<span class="lineNum">     453 </span>            :   // Constructs a ReturnAction object from the value to be returned.
<span class="lineNum">     454 </span>            :   // 'value' is passed by value instead of by const reference in order
<span class="lineNum">     455 </span>            :   // to allow Return(&quot;string literal&quot;) to compile.
<span class="lineNum">     456 </span>            :   explicit ReturnAction(R value) : value_(value) {}
<span class="lineNum">     457 </span>            : 
<span class="lineNum">     458 </span>            :   // This template type conversion operator allows Return(x) to be
<span class="lineNum">     459 </span>            :   // used in ANY function that returns x's type.
<span class="lineNum">     460 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     461 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     462 </span>            :     // Assert statement belongs here because this is the best place to verify
<span class="lineNum">     463 </span>            :     // conditions on F. It produces the clearest error messages
<span class="lineNum">     464 </span>            :     // in most compilers.
<span class="lineNum">     465 </span>            :     // Impl really belongs in this scope as a local class but can't
<span class="lineNum">     466 </span>            :     // because MSVC produces duplicate symbols in different translation units
<span class="lineNum">     467 </span>            :     // in this case. Until MS fixes that bug we put Impl into the class scope
<span class="lineNum">     468 </span>            :     // and put the typedef both here (for use in assert statement) and
<span class="lineNum">     469 </span>            :     // in the Impl class. But both definitions must be the same.
<span class="lineNum">     470 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     471 </span>            :     GTEST_COMPILE_ASSERT_(
<span class="lineNum">     472 </span>            :         !internal::is_reference&lt;Result&gt;::value,
<span class="lineNum">     473 </span>            :         use_ReturnRef_instead_of_Return_to_return_a_reference);
<span class="lineNum">     474 </span>            :     return Action&lt;F&gt;(new Impl&lt;F&gt;(value_));
<span class="lineNum">     475 </span>            :   }
<span class="lineNum">     476 </span>            : 
<span class="lineNum">     477 </span>            :  private:
<span class="lineNum">     478 </span>            :   // Implements the Return(x) action for a particular function type F.
<span class="lineNum">     479 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     480 </span>            :   class Impl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     481 </span>            :    public:
<span class="lineNum">     482 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     483 </span>            :     typedef typename Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     484 </span>            : 
<span class="lineNum">     485 </span>            :     // The implicit cast is necessary when Result has more than one
<span class="lineNum">     486 </span>            :     // single-argument constructor (e.g. Result is std::vector&lt;int&gt;) and R
<span class="lineNum">     487 </span>            :     // has a type conversion operator template.  In that case, value_(value)
<span class="lineNum">     488 </span>            :     // won't compile as the compiler doesn't known which constructor of
<span class="lineNum">     489 </span>            :     // Result to call.  ImplicitCast_ forces the compiler to convert R to
<span class="lineNum">     490 </span>            :     // Result without considering explicit constructors, thus resolving the
<span class="lineNum">     491 </span>            :     // ambiguity. value_ is then initialized using its copy constructor.
<span class="lineNum">     492 </span>            :     explicit Impl(R value)
<span class="lineNum">     493 </span>            :         : value_(::testing::internal::ImplicitCast_&lt;Result&gt;(value)) {}
<span class="lineNum">     494 </span>            : 
<span class="lineNum">     495 </span>            :     virtual Result Perform(const ArgumentTuple&amp;) { return value_; }
<span class="lineNum">     496 </span>            : 
<span class="lineNum">     497 </span>            :    private:
<span class="lineNum">     498 </span>            :     GTEST_COMPILE_ASSERT_(!internal::is_reference&lt;Result&gt;::value,
<span class="lineNum">     499 </span>            :                           Result_cannot_be_a_reference_type);
<span class="lineNum">     500 </span>            :     Result value_;
<span class="lineNum">     501 </span>            : 
<span class="lineNum">     502 </span>            :     GTEST_DISALLOW_ASSIGN_(Impl);
<span class="lineNum">     503 </span>            :   };
<span class="lineNum">     504 </span>            : 
<span class="lineNum">     505 </span>            :   R value_;
<span class="lineNum">     506 </span>            : 
<span class="lineNum">     507 </span>            :   GTEST_DISALLOW_ASSIGN_(ReturnAction);
<span class="lineNum">     508 </span>            : };
<span class="lineNum">     509 </span>            : 
<span class="lineNum">     510 </span>            : // Implements the ReturnNull() action.
<span class="lineNum">     511 </span>            : class ReturnNullAction {
<span class="lineNum">     512 </span>            :  public:
<span class="lineNum">     513 </span>            :   // Allows ReturnNull() to be used in any pointer-returning function.
<span class="lineNum">     514 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     515 </span>            :   static Result Perform(const ArgumentTuple&amp;) {
<span class="lineNum">     516 </span>            :     GTEST_COMPILE_ASSERT_(internal::is_pointer&lt;Result&gt;::value,
<span class="lineNum">     517 </span>            :                           ReturnNull_can_be_used_to_return_a_pointer_only);
<span class="lineNum">     518 </span>            :     return NULL;
<span class="lineNum">     519 </span>            :   }
<span class="lineNum">     520 </span>            : };
<span class="lineNum">     521 </span>            : 
<span class="lineNum">     522 </span>            : // Implements the Return() action.
<span class="lineNum">     523 </span>            : class ReturnVoidAction {
<span class="lineNum">     524 </span>            :  public:
<span class="lineNum">     525 </span>            :   // Allows Return() to be used in any void-returning function.
<span class="lineNum">     526 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     527 </span>            :   static void Perform(const ArgumentTuple&amp;) {
<span class="lineNum">     528 </span>            :     CompileAssertTypesEqual&lt;void, Result&gt;();
<span class="lineNum">     529 </span>            :   }
<span class="lineNum">     530 </span>            : };
<span class="lineNum">     531 </span>            : 
<span class="lineNum">     532 </span>            : // Implements the polymorphic ReturnRef(x) action, which can be used
<span class="lineNum">     533 </span>            : // in any function that returns a reference to the type of x,
<span class="lineNum">     534 </span>            : // regardless of the argument types.
<span class="lineNum">     535 </span>            : template &lt;typename T&gt;
<span class="lineNum">     536 </span>            : class ReturnRefAction {
<span class="lineNum">     537 </span>            :  public:
<span class="lineNum">     538 </span>            :   // Constructs a ReturnRefAction object from the reference to be returned.
<span class="lineNum">     539 </span>            :   explicit ReturnRefAction(T&amp; ref) : ref_(ref) {}  // NOLINT
<span class="lineNum">     540 </span>            : 
<span class="lineNum">     541 </span>            :   // This template type conversion operator allows ReturnRef(x) to be
<span class="lineNum">     542 </span>            :   // used in ANY function that returns a reference to x's type.
<span class="lineNum">     543 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     544 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     545 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     546 </span>            :     // Asserts that the function return type is a reference.  This
<span class="lineNum">     547 </span>            :     // catches the user error of using ReturnRef(x) when Return(x)
<span class="lineNum">     548 </span>            :     // should be used, and generates some helpful error message.
<span class="lineNum">     549 </span>            :     GTEST_COMPILE_ASSERT_(internal::is_reference&lt;Result&gt;::value,
<span class="lineNum">     550 </span>            :                           use_Return_instead_of_ReturnRef_to_return_a_value);
<span class="lineNum">     551 </span>            :     return Action&lt;F&gt;(new Impl&lt;F&gt;(ref_));
<span class="lineNum">     552 </span>            :   }
<span class="lineNum">     553 </span>            : 
<span class="lineNum">     554 </span>            :  private:
<span class="lineNum">     555 </span>            :   // Implements the ReturnRef(x) action for a particular function type F.
<span class="lineNum">     556 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     557 </span>            :   class Impl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     558 </span>            :    public:
<span class="lineNum">     559 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     560 </span>            :     typedef typename Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     561 </span>            : 
<span class="lineNum">     562 </span>            :     explicit Impl(T&amp; ref) : ref_(ref) {}  // NOLINT
<span class="lineNum">     563 </span>            : 
<span class="lineNum">     564 </span>            :     virtual Result Perform(const ArgumentTuple&amp;) {
<span class="lineNum">     565 </span>            :       return ref_;
<span class="lineNum">     566 </span>            :     }
<span class="lineNum">     567 </span>            : 
<span class="lineNum">     568 </span>            :    private:
<span class="lineNum">     569 </span>            :     T&amp; ref_;
<span class="lineNum">     570 </span>            : 
<span class="lineNum">     571 </span>            :     GTEST_DISALLOW_ASSIGN_(Impl);
<span class="lineNum">     572 </span>            :   };
<span class="lineNum">     573 </span>            : 
<span class="lineNum">     574 </span>            :   T&amp; ref_;
<span class="lineNum">     575 </span>            : 
<span class="lineNum">     576 </span>            :   GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
<span class="lineNum">     577 </span>            : };
<span class="lineNum">     578 </span>            : 
<span class="lineNum">     579 </span>            : // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
<span class="lineNum">     580 </span>            : // used in any function that returns a reference to the type of x,
<span class="lineNum">     581 </span>            : // regardless of the argument types.
<span class="lineNum">     582 </span>            : template &lt;typename T&gt;
<span class="lineNum">     583 </span>            : class ReturnRefOfCopyAction {
<span class="lineNum">     584 </span>            :  public:
<span class="lineNum">     585 </span>            :   // Constructs a ReturnRefOfCopyAction object from the reference to
<span class="lineNum">     586 </span>            :   // be returned.
<span class="lineNum">     587 </span>            :   explicit ReturnRefOfCopyAction(const T&amp; value) : value_(value) {}  // NOLINT
<span class="lineNum">     588 </span>            : 
<span class="lineNum">     589 </span>            :   // This template type conversion operator allows ReturnRefOfCopy(x) to be
<span class="lineNum">     590 </span>            :   // used in ANY function that returns a reference to x's type.
<span class="lineNum">     591 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     592 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     593 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     594 </span>            :     // Asserts that the function return type is a reference.  This
<span class="lineNum">     595 </span>            :     // catches the user error of using ReturnRefOfCopy(x) when Return(x)
<span class="lineNum">     596 </span>            :     // should be used, and generates some helpful error message.
<span class="lineNum">     597 </span>            :     GTEST_COMPILE_ASSERT_(
<span class="lineNum">     598 </span>            :         internal::is_reference&lt;Result&gt;::value,
<span class="lineNum">     599 </span>            :         use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
<span class="lineNum">     600 </span>            :     return Action&lt;F&gt;(new Impl&lt;F&gt;(value_));
<span class="lineNum">     601 </span>            :   }
<span class="lineNum">     602 </span>            : 
<span class="lineNum">     603 </span>            :  private:
<span class="lineNum">     604 </span>            :   // Implements the ReturnRefOfCopy(x) action for a particular function type F.
<span class="lineNum">     605 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     606 </span>            :   class Impl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     607 </span>            :    public:
<span class="lineNum">     608 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     609 </span>            :     typedef typename Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     610 </span>            : 
<span class="lineNum">     611 </span>            :     explicit Impl(const T&amp; value) : value_(value) {}  // NOLINT
<span class="lineNum">     612 </span>            : 
<span class="lineNum">     613 </span>            :     virtual Result Perform(const ArgumentTuple&amp;) {
<span class="lineNum">     614 </span>            :       return value_;
<span class="lineNum">     615 </span>            :     }
<span class="lineNum">     616 </span>            : 
<span class="lineNum">     617 </span>            :    private:
<span class="lineNum">     618 </span>            :     T value_;
<span class="lineNum">     619 </span>            : 
<span class="lineNum">     620 </span>            :     GTEST_DISALLOW_ASSIGN_(Impl);
<span class="lineNum">     621 </span>            :   };
<span class="lineNum">     622 </span>            : 
<span class="lineNum">     623 </span>            :   const T value_;
<span class="lineNum">     624 </span>            : 
<span class="lineNum">     625 </span>            :   GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
<span class="lineNum">     626 </span>            : };
<span class="lineNum">     627 </span>            : 
<span class="lineNum">     628 </span>            : // Implements the polymorphic DoDefault() action.
<span class="lineNum">     629 </span>            : class DoDefaultAction {
<span class="lineNum">     630 </span>            :  public:
<span class="lineNum">     631 </span>            :   // This template type conversion operator allows DoDefault() to be
<a name="632"><span class="lineNum">     632 </span>            :   // used in any function.</a>
<span class="lineNum">     633 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     634 </span><span class="lineNoCov">          0 :   operator Action&lt;F&gt;() const { return Action&lt;F&gt;(NULL); }</span>
<span class="lineNum">     635 </span>            : };
<span class="lineNum">     636 </span>            : 
<span class="lineNum">     637 </span>            : // Implements the Assign action to set a given pointer referent to a
<span class="lineNum">     638 </span>            : // particular value.
<span class="lineNum">     639 </span>            : template &lt;typename T1, typename T2&gt;
<span class="lineNum">     640 </span>            : class AssignAction {
<span class="lineNum">     641 </span>            :  public:
<span class="lineNum">     642 </span>            :   AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
<span class="lineNum">     643 </span>            : 
<span class="lineNum">     644 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     645 </span>            :   void Perform(const ArgumentTuple&amp; /* args */) const {
<span class="lineNum">     646 </span>            :     *ptr_ = value_;
<span class="lineNum">     647 </span>            :   }
<span class="lineNum">     648 </span>            : 
<span class="lineNum">     649 </span>            :  private:
<span class="lineNum">     650 </span>            :   T1* const ptr_;
<span class="lineNum">     651 </span>            :   const T2 value_;
<span class="lineNum">     652 </span>            : 
<span class="lineNum">     653 </span>            :   GTEST_DISALLOW_ASSIGN_(AssignAction);
<span class="lineNum">     654 </span>            : };
<span class="lineNum">     655 </span>            : 
<span class="lineNum">     656 </span>            : #if !GTEST_OS_WINDOWS_MOBILE
<span class="lineNum">     657 </span>            : 
<span class="lineNum">     658 </span>            : // Implements the SetErrnoAndReturn action to simulate return from
<span class="lineNum">     659 </span>            : // various system calls and libc functions.
<span class="lineNum">     660 </span>            : template &lt;typename T&gt;
<span class="lineNum">     661 </span>            : class SetErrnoAndReturnAction {
<span class="lineNum">     662 </span>            :  public:
<span class="lineNum">     663 </span>            :   SetErrnoAndReturnAction(int errno_value, T result)
<span class="lineNum">     664 </span>            :       : errno_(errno_value),
<span class="lineNum">     665 </span>            :         result_(result) {}
<span class="lineNum">     666 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     667 </span>            :   Result Perform(const ArgumentTuple&amp; /* args */) const {
<span class="lineNum">     668 </span>            :     errno = errno_;
<span class="lineNum">     669 </span>            :     return result_;
<span class="lineNum">     670 </span>            :   }
<span class="lineNum">     671 </span>            : 
<span class="lineNum">     672 </span>            :  private:
<span class="lineNum">     673 </span>            :   const int errno_;
<span class="lineNum">     674 </span>            :   const T result_;
<span class="lineNum">     675 </span>            : 
<span class="lineNum">     676 </span>            :   GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
<span class="lineNum">     677 </span>            : };
<span class="lineNum">     678 </span>            : 
<span class="lineNum">     679 </span>            : #endif  // !GTEST_OS_WINDOWS_MOBILE
<span class="lineNum">     680 </span>            : 
<span class="lineNum">     681 </span>            : // Implements the SetArgumentPointee&lt;N&gt;(x) action for any function
<span class="lineNum">     682 </span>            : // whose N-th argument (0-based) is a pointer to x's type.  The
<span class="lineNum">     683 </span>            : // template parameter kIsProto is true iff type A is ProtocolMessage,
<span class="lineNum">     684 </span>            : // proto2::Message, or a sub-class of those.
<span class="lineNum">     685 </span>            : template &lt;size_t N, typename A, bool kIsProto&gt;
<span class="lineNum">     686 </span>            : class SetArgumentPointeeAction {
<span class="lineNum">     687 </span>            :  public:
<span class="lineNum">     688 </span>            :   // Constructs an action that sets the variable pointed to by the
<span class="lineNum">     689 </span>            :   // N-th function argument to 'value'.
<span class="lineNum">     690 </span>            :   explicit SetArgumentPointeeAction(const A&amp; value) : value_(value) {}
<span class="lineNum">     691 </span>            : 
<span class="lineNum">     692 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     693 </span>            :   void Perform(const ArgumentTuple&amp; args) const {
<span class="lineNum">     694 </span>            :     CompileAssertTypesEqual&lt;void, Result&gt;();
<span class="lineNum">     695 </span>            :     *::std::tr1::get&lt;N&gt;(args) = value_;
<span class="lineNum">     696 </span>            :   }
<span class="lineNum">     697 </span>            : 
<span class="lineNum">     698 </span>            :  private:
<span class="lineNum">     699 </span>            :   const A value_;
<span class="lineNum">     700 </span>            : 
<span class="lineNum">     701 </span>            :   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
<span class="lineNum">     702 </span>            : };
<span class="lineNum">     703 </span>            : 
<span class="lineNum">     704 </span>            : template &lt;size_t N, typename Proto&gt;
<span class="lineNum">     705 </span>            : class SetArgumentPointeeAction&lt;N, Proto, true&gt; {
<span class="lineNum">     706 </span>            :  public:
<span class="lineNum">     707 </span>            :   // Constructs an action that sets the variable pointed to by the
<span class="lineNum">     708 </span>            :   // N-th function argument to 'proto'.  Both ProtocolMessage and
<span class="lineNum">     709 </span>            :   // proto2::Message have the CopyFrom() method, so the same
<span class="lineNum">     710 </span>            :   // implementation works for both.
<span class="lineNum">     711 </span>            :   explicit SetArgumentPointeeAction(const Proto&amp; proto) : proto_(new Proto) {
<span class="lineNum">     712 </span>            :     proto_-&gt;CopyFrom(proto);
<span class="lineNum">     713 </span>            :   }
<span class="lineNum">     714 </span>            : 
<span class="lineNum">     715 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     716 </span>            :   void Perform(const ArgumentTuple&amp; args) const {
<span class="lineNum">     717 </span>            :     CompileAssertTypesEqual&lt;void, Result&gt;();
<span class="lineNum">     718 </span>            :     ::std::tr1::get&lt;N&gt;(args)-&gt;CopyFrom(*proto_);
<span class="lineNum">     719 </span>            :   }
<span class="lineNum">     720 </span>            : 
<span class="lineNum">     721 </span>            :  private:
<span class="lineNum">     722 </span>            :   const internal::linked_ptr&lt;Proto&gt; proto_;
<span class="lineNum">     723 </span>            : 
<span class="lineNum">     724 </span>            :   GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
<span class="lineNum">     725 </span>            : };
<span class="lineNum">     726 </span>            : 
<span class="lineNum">     727 </span>            : // Implements the InvokeWithoutArgs(f) action.  The template argument
<span class="lineNum">     728 </span>            : // FunctionImpl is the implementation type of f, which can be either a
<span class="lineNum">     729 </span>            : // function pointer or a functor.  InvokeWithoutArgs(f) can be used as an
<span class="lineNum">     730 </span>            : // Action&lt;F&gt; as long as f's type is compatible with F (i.e. f can be
<span class="lineNum">     731 </span>            : // assigned to a tr1::function&lt;F&gt;).
<span class="lineNum">     732 </span>            : template &lt;typename FunctionImpl&gt;
<span class="lineNum">     733 </span>            : class InvokeWithoutArgsAction {
<span class="lineNum">     734 </span>            :  public:
<span class="lineNum">     735 </span>            :   // The c'tor makes a copy of function_impl (either a function
<span class="lineNum">     736 </span>            :   // pointer or a functor).
<span class="lineNum">     737 </span>            :   explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
<span class="lineNum">     738 </span>            :       : function_impl_(function_impl) {}
<span class="lineNum">     739 </span>            : 
<span class="lineNum">     740 </span>            :   // Allows InvokeWithoutArgs(f) to be used as any action whose type is
<span class="lineNum">     741 </span>            :   // compatible with f.
<span class="lineNum">     742 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     743 </span>            :   Result Perform(const ArgumentTuple&amp;) { return function_impl_(); }
<span class="lineNum">     744 </span>            : 
<span class="lineNum">     745 </span>            :  private:
<span class="lineNum">     746 </span>            :   FunctionImpl function_impl_;
<span class="lineNum">     747 </span>            : 
<span class="lineNum">     748 </span>            :   GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
<span class="lineNum">     749 </span>            : };
<span class="lineNum">     750 </span>            : 
<span class="lineNum">     751 </span>            : // Implements the InvokeWithoutArgs(object_ptr, &amp;Class::Method) action.
<span class="lineNum">     752 </span>            : template &lt;class Class, typename MethodPtr&gt;
<span class="lineNum">     753 </span>            : class InvokeMethodWithoutArgsAction {
<span class="lineNum">     754 </span>            :  public:
<span class="lineNum">     755 </span>            :   InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
<span class="lineNum">     756 </span>            :       : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
<span class="lineNum">     757 </span>            : 
<span class="lineNum">     758 </span>            :   template &lt;typename Result, typename ArgumentTuple&gt;
<span class="lineNum">     759 </span>            :   Result Perform(const ArgumentTuple&amp;) const {
<span class="lineNum">     760 </span>            :     return (obj_ptr_-&gt;*method_ptr_)();
<span class="lineNum">     761 </span>            :   }
<span class="lineNum">     762 </span>            : 
<span class="lineNum">     763 </span>            :  private:
<span class="lineNum">     764 </span>            :   Class* const obj_ptr_;
<span class="lineNum">     765 </span>            :   const MethodPtr method_ptr_;
<span class="lineNum">     766 </span>            : 
<span class="lineNum">     767 </span>            :   GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
<span class="lineNum">     768 </span>            : };
<span class="lineNum">     769 </span>            : 
<span class="lineNum">     770 </span>            : // Implements the IgnoreResult(action) action.
<span class="lineNum">     771 </span>            : template &lt;typename A&gt;
<span class="lineNum">     772 </span>            : class IgnoreResultAction {
<span class="lineNum">     773 </span>            :  public:
<span class="lineNum">     774 </span>            :   explicit IgnoreResultAction(const A&amp; action) : action_(action) {}
<span class="lineNum">     775 </span>            : 
<span class="lineNum">     776 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     777 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     778 </span>            :     // Assert statement belongs here because this is the best place to verify
<span class="lineNum">     779 </span>            :     // conditions on F. It produces the clearest error messages
<span class="lineNum">     780 </span>            :     // in most compilers.
<span class="lineNum">     781 </span>            :     // Impl really belongs in this scope as a local class but can't
<span class="lineNum">     782 </span>            :     // because MSVC produces duplicate symbols in different translation units
<span class="lineNum">     783 </span>            :     // in this case. Until MS fixes that bug we put Impl into the class scope
<span class="lineNum">     784 </span>            :     // and put the typedef both here (for use in assert statement) and
<span class="lineNum">     785 </span>            :     // in the Impl class. But both definitions must be the same.
<span class="lineNum">     786 </span>            :     typedef typename internal::Function&lt;F&gt;::Result Result;
<span class="lineNum">     787 </span>            : 
<span class="lineNum">     788 </span>            :     // Asserts at compile time that F returns void.
<span class="lineNum">     789 </span>            :     CompileAssertTypesEqual&lt;void, Result&gt;();
<span class="lineNum">     790 </span>            : 
<span class="lineNum">     791 </span>            :     return Action&lt;F&gt;(new Impl&lt;F&gt;(action_));
<span class="lineNum">     792 </span>            :   }
<span class="lineNum">     793 </span>            : 
<span class="lineNum">     794 </span>            :  private:
<span class="lineNum">     795 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     796 </span>            :   class Impl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     797 </span>            :    public:
<span class="lineNum">     798 </span>            :     typedef typename internal::Function&lt;F&gt;::Result Result;
<span class="lineNum">     799 </span>            :     typedef typename internal::Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     800 </span>            : 
<span class="lineNum">     801 </span>            :     explicit Impl(const A&amp; action) : action_(action) {}
<span class="lineNum">     802 </span>            : 
<span class="lineNum">     803 </span>            :     virtual void Perform(const ArgumentTuple&amp; args) {
<span class="lineNum">     804 </span>            :       // Performs the action and ignores its result.
<span class="lineNum">     805 </span>            :       action_.Perform(args);
<span class="lineNum">     806 </span>            :     }
<span class="lineNum">     807 </span>            : 
<span class="lineNum">     808 </span>            :    private:
<span class="lineNum">     809 </span>            :     // Type OriginalFunction is the same as F except that its return
<span class="lineNum">     810 </span>            :     // type is IgnoredValue.
<span class="lineNum">     811 </span>            :     typedef typename internal::Function&lt;F&gt;::MakeResultIgnoredValue
<span class="lineNum">     812 </span>            :         OriginalFunction;
<span class="lineNum">     813 </span>            : 
<span class="lineNum">     814 </span>            :     const Action&lt;OriginalFunction&gt; action_;
<span class="lineNum">     815 </span>            : 
<span class="lineNum">     816 </span>            :     GTEST_DISALLOW_ASSIGN_(Impl);
<span class="lineNum">     817 </span>            :   };
<span class="lineNum">     818 </span>            : 
<span class="lineNum">     819 </span>            :   const A action_;
<span class="lineNum">     820 </span>            : 
<span class="lineNum">     821 </span>            :   GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
<span class="lineNum">     822 </span>            : };
<span class="lineNum">     823 </span>            : 
<span class="lineNum">     824 </span>            : // A ReferenceWrapper&lt;T&gt; object represents a reference to type T,
<span class="lineNum">     825 </span>            : // which can be either const or not.  It can be explicitly converted
<span class="lineNum">     826 </span>            : // from, and implicitly converted to, a T&amp;.  Unlike a reference,
<span class="lineNum">     827 </span>            : // ReferenceWrapper&lt;T&gt; can be copied and can survive template type
<span class="lineNum">     828 </span>            : // inference.  This is used to support by-reference arguments in the
<span class="lineNum">     829 </span>            : // InvokeArgument&lt;N&gt;(...) action.  The idea was from &quot;reference
<span class="lineNum">     830 </span>            : // wrappers&quot; in tr1, which we don't have in our source tree yet.
<span class="lineNum">     831 </span>            : template &lt;typename T&gt;
<span class="lineNum">     832 </span>            : class ReferenceWrapper {
<span class="lineNum">     833 </span>            :  public:
<span class="lineNum">     834 </span>            :   // Constructs a ReferenceWrapper&lt;T&gt; object from a T&amp;.
<span class="lineNum">     835 </span>            :   explicit ReferenceWrapper(T&amp; l_value) : pointer_(&amp;l_value) {}  // NOLINT
<span class="lineNum">     836 </span>            : 
<span class="lineNum">     837 </span>            :   // Allows a ReferenceWrapper&lt;T&gt; object to be implicitly converted to
<span class="lineNum">     838 </span>            :   // a T&amp;.
<span class="lineNum">     839 </span>            :   operator T&amp;() const { return *pointer_; }
<span class="lineNum">     840 </span>            :  private:
<span class="lineNum">     841 </span>            :   T* pointer_;
<span class="lineNum">     842 </span>            : };
<span class="lineNum">     843 </span>            : 
<span class="lineNum">     844 </span>            : // Allows the expression ByRef(x) to be printed as a reference to x.
<span class="lineNum">     845 </span>            : template &lt;typename T&gt;
<span class="lineNum">     846 </span>            : void PrintTo(const ReferenceWrapper&lt;T&gt;&amp; ref, ::std::ostream* os) {
<span class="lineNum">     847 </span>            :   T&amp; value = ref;
<span class="lineNum">     848 </span>            :   UniversalPrinter&lt;T&amp;&gt;::Print(value, os);
<span class="lineNum">     849 </span>            : }
<span class="lineNum">     850 </span>            : 
<span class="lineNum">     851 </span>            : // Does two actions sequentially.  Used for implementing the DoAll(a1,
<span class="lineNum">     852 </span>            : // a2, ...) action.
<span class="lineNum">     853 </span>            : template &lt;typename Action1, typename Action2&gt;
<span class="lineNum">     854 </span>            : class DoBothAction {
<span class="lineNum">     855 </span>            :  public:
<span class="lineNum">     856 </span>            :   DoBothAction(Action1 action1, Action2 action2)
<span class="lineNum">     857 </span>            :       : action1_(action1), action2_(action2) {}
<span class="lineNum">     858 </span>            : 
<span class="lineNum">     859 </span>            :   // This template type conversion operator allows DoAll(a1, ..., a_n)
<span class="lineNum">     860 </span>            :   // to be used in ANY function of compatible type.
<span class="lineNum">     861 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     862 </span>            :   operator Action&lt;F&gt;() const {
<span class="lineNum">     863 </span>            :     return Action&lt;F&gt;(new Impl&lt;F&gt;(action1_, action2_));
<span class="lineNum">     864 </span>            :   }
<span class="lineNum">     865 </span>            : 
<span class="lineNum">     866 </span>            :  private:
<span class="lineNum">     867 </span>            :   // Implements the DoAll(...) action for a particular function type F.
<span class="lineNum">     868 </span>            :   template &lt;typename F&gt;
<span class="lineNum">     869 </span>            :   class Impl : public ActionInterface&lt;F&gt; {
<span class="lineNum">     870 </span>            :    public:
<span class="lineNum">     871 </span>            :     typedef typename Function&lt;F&gt;::Result Result;
<span class="lineNum">     872 </span>            :     typedef typename Function&lt;F&gt;::ArgumentTuple ArgumentTuple;
<span class="lineNum">     873 </span>            :     typedef typename Function&lt;F&gt;::MakeResultVoid VoidResult;
<span class="lineNum">     874 </span>            : 
<span class="lineNum">     875 </span>            :     Impl(const Action&lt;VoidResult&gt;&amp; action1, const Action&lt;F&gt;&amp; action2)
<span class="lineNum">     876 </span>            :         : action1_(action1), action2_(action2) {}
<span class="lineNum">     877 </span>            : 
<span class="lineNum">     878 </span>            :     virtual Result Perform(const ArgumentTuple&amp; args) {
<span class="lineNum">     879 </span>            :       action1_.Perform(args);
<span class="lineNum">     880 </span>            :       return action2_.Perform(args);
<span class="lineNum">     881 </span>            :     }
<span class="lineNum">     882 </span>            : 
<span class="lineNum">     883 </span>            :    private:
<span class="lineNum">     884 </span>            :     const Action&lt;VoidResult&gt; action1_;
<span class="lineNum">     885 </span>            :     const Action&lt;F&gt; action2_;
<span class="lineNum">     886 </span>            : 
<span class="lineNum">     887 </span>            :     GTEST_DISALLOW_ASSIGN_(Impl);
<span class="lineNum">     888 </span>            :   };
<span class="lineNum">     889 </span>            : 
<span class="lineNum">     890 </span>            :   Action1 action1_;
<span class="lineNum">     891 </span>            :   Action2 action2_;
<span class="lineNum">     892 </span>            : 
<span class="lineNum">     893 </span>            :   GTEST_DISALLOW_ASSIGN_(DoBothAction);
<span class="lineNum">     894 </span>            : };
<span class="lineNum">     895 </span>            : 
<span class="lineNum">     896 </span>            : }  // namespace internal
<span class="lineNum">     897 </span>            : 
<span class="lineNum">     898 </span>            : // An Unused object can be implicitly constructed from ANY value.
<span class="lineNum">     899 </span>            : // This is handy when defining actions that ignore some or all of the
<span class="lineNum">     900 </span>            : // mock function arguments.  For example, given
<span class="lineNum">     901 </span>            : //
<span class="lineNum">     902 </span>            : //   MOCK_METHOD3(Foo, double(const string&amp; label, double x, double y));
<span class="lineNum">     903 </span>            : //   MOCK_METHOD3(Bar, double(int index, double x, double y));
<span class="lineNum">     904 </span>            : //
<span class="lineNum">     905 </span>            : // instead of
<span class="lineNum">     906 </span>            : //
<span class="lineNum">     907 </span>            : //   double DistanceToOriginWithLabel(const string&amp; label, double x, double y) {
<span class="lineNum">     908 </span>            : //     return sqrt(x*x + y*y);
<span class="lineNum">     909 </span>            : //   }
<span class="lineNum">     910 </span>            : //   double DistanceToOriginWithIndex(int index, double x, double y) {
<span class="lineNum">     911 </span>            : //     return sqrt(x*x + y*y);
<span class="lineNum">     912 </span>            : //   }
<span class="lineNum">     913 </span>            : //   ...
<span class="lineNum">     914 </span>            : //   EXEPCT_CALL(mock, Foo(&quot;abc&quot;, _, _))
<span class="lineNum">     915 </span>            : //       .WillOnce(Invoke(DistanceToOriginWithLabel));
<span class="lineNum">     916 </span>            : //   EXEPCT_CALL(mock, Bar(5, _, _))
<span class="lineNum">     917 </span>            : //       .WillOnce(Invoke(DistanceToOriginWithIndex));
<span class="lineNum">     918 </span>            : //
<span class="lineNum">     919 </span>            : // you could write
<span class="lineNum">     920 </span>            : //
<span class="lineNum">     921 </span>            : //   // We can declare any uninteresting argument as Unused.
<span class="lineNum">     922 </span>            : //   double DistanceToOrigin(Unused, double x, double y) {
<span class="lineNum">     923 </span>            : //     return sqrt(x*x + y*y);
<span class="lineNum">     924 </span>            : //   }
<span class="lineNum">     925 </span>            : //   ...
<span class="lineNum">     926 </span>            : //   EXEPCT_CALL(mock, Foo(&quot;abc&quot;, _, _)).WillOnce(Invoke(DistanceToOrigin));
<span class="lineNum">     927 </span>            : //   EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
<span class="lineNum">     928 </span>            : typedef internal::IgnoredValue Unused;
<span class="lineNum">     929 </span>            : 
<span class="lineNum">     930 </span>            : // This constructor allows us to turn an Action&lt;From&gt; object into an
<span class="lineNum">     931 </span>            : // Action&lt;To&gt;, as long as To's arguments can be implicitly converted
<span class="lineNum">     932 </span>            : // to From's and From's return type cann be implicitly converted to
<span class="lineNum">     933 </span>            : // To's.
<span class="lineNum">     934 </span>            : template &lt;typename To&gt;
<span class="lineNum">     935 </span>            : template &lt;typename From&gt;
<span class="lineNum">     936 </span>            : Action&lt;To&gt;::Action(const Action&lt;From&gt;&amp; from)
<span class="lineNum">     937 </span>            :     : impl_(new internal::ActionAdaptor&lt;To, From&gt;(from)) {}
<span class="lineNum">     938 </span>            : 
<span class="lineNum">     939 </span>            : // Creates an action that returns 'value'.  'value' is passed by value
<span class="lineNum">     940 </span>            : // instead of const reference - otherwise Return(&quot;string literal&quot;)
<span class="lineNum">     941 </span>            : // will trigger a compiler error about using array as initializer.
<span class="lineNum">     942 </span>            : template &lt;typename R&gt;
<span class="lineNum">     943 </span>            : internal::ReturnAction&lt;R&gt; Return(R value) {
<span class="lineNum">     944 </span>            :   return internal::ReturnAction&lt;R&gt;(value);
<span class="lineNum">     945 </span>            : }
<span class="lineNum">     946 </span>            : 
<span class="lineNum">     947 </span>            : // Creates an action that returns NULL.
<span class="lineNum">     948 </span>            : inline PolymorphicAction&lt;internal::ReturnNullAction&gt; ReturnNull() {
<span class="lineNum">     949 </span>            :   return MakePolymorphicAction(internal::ReturnNullAction());
<span class="lineNum">     950 </span>            : }
<span class="lineNum">     951 </span>            : 
<span class="lineNum">     952 </span>            : // Creates an action that returns from a void function.
<span class="lineNum">     953 </span>            : inline PolymorphicAction&lt;internal::ReturnVoidAction&gt; Return() {
<span class="lineNum">     954 </span>            :   return MakePolymorphicAction(internal::ReturnVoidAction());
<span class="lineNum">     955 </span>            : }
<span class="lineNum">     956 </span>            : 
<span class="lineNum">     957 </span>            : // Creates an action that returns the reference to a variable.
<span class="lineNum">     958 </span>            : template &lt;typename R&gt;
<span class="lineNum">     959 </span>            : inline internal::ReturnRefAction&lt;R&gt; ReturnRef(R&amp; x) {  // NOLINT
<span class="lineNum">     960 </span>            :   return internal::ReturnRefAction&lt;R&gt;(x);
<span class="lineNum">     961 </span>            : }
<span class="lineNum">     962 </span>            : 
<span class="lineNum">     963 </span>            : // Creates an action that returns the reference to a copy of the
<span class="lineNum">     964 </span>            : // argument.  The copy is created when the action is constructed and
<span class="lineNum">     965 </span>            : // lives as long as the action.
<span class="lineNum">     966 </span>            : template &lt;typename R&gt;
<span class="lineNum">     967 </span>            : inline internal::ReturnRefOfCopyAction&lt;R&gt; ReturnRefOfCopy(const R&amp; x) {
<span class="lineNum">     968 </span>            :   return internal::ReturnRefOfCopyAction&lt;R&gt;(x);
<span class="lineNum">     969 </span>            : }
<a name="970"><span class="lineNum">     970 </span>            : </a>
<span class="lineNum">     971 </span>            : // Creates an action that does the default action for the give mock function.
<span class="lineNum">     972 </span><span class="lineNoCov">          0 : inline internal::DoDefaultAction DoDefault() {</span>
<span class="lineNum">     973 </span><span class="lineNoCov">          0 :   return internal::DoDefaultAction();</span>
<span class="lineNum">     974 </span>            : }
<span class="lineNum">     975 </span>            : 
<span class="lineNum">     976 </span>            : // Creates an action that sets the variable pointed by the N-th
<span class="lineNum">     977 </span>            : // (0-based) function argument to 'value'.
<span class="lineNum">     978 </span>            : template &lt;size_t N, typename T&gt;
<span class="lineNum">     979 </span>            : PolymorphicAction&lt;
<span class="lineNum">     980 </span>            :   internal::SetArgumentPointeeAction&lt;
<span class="lineNum">     981 </span>            :     N, T, internal::IsAProtocolMessage&lt;T&gt;::value&gt; &gt;
<span class="lineNum">     982 </span>            : SetArgPointee(const T&amp; x) {
<span class="lineNum">     983 </span>            :   return MakePolymorphicAction(internal::SetArgumentPointeeAction&lt;
<span class="lineNum">     984 </span>            :       N, T, internal::IsAProtocolMessage&lt;T&gt;::value&gt;(x));
<span class="lineNum">     985 </span>            : }
<span class="lineNum">     986 </span>            : 
<span class="lineNum">     987 </span>            : #if !((GTEST_GCC_VER_ &amp;&amp; GTEST_GCC_VER_ &lt; 40000) || GTEST_OS_SYMBIAN)
<span class="lineNum">     988 </span>            : // This overload allows SetArgPointee() to accept a string literal.
<span class="lineNum">     989 </span>            : // GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
<span class="lineNum">     990 </span>            : // this overload from the templated version and emit a compile error.
<span class="lineNum">     991 </span>            : template &lt;size_t N&gt;
<span class="lineNum">     992 </span>            : PolymorphicAction&lt;
<span class="lineNum">     993 </span>            :   internal::SetArgumentPointeeAction&lt;N, const char*, false&gt; &gt;
<span class="lineNum">     994 </span>            : SetArgPointee(const char* p) {
<span class="lineNum">     995 </span>            :   return MakePolymorphicAction(internal::SetArgumentPointeeAction&lt;
<span class="lineNum">     996 </span>            :       N, const char*, false&gt;(p));
<span class="lineNum">     997 </span>            : }
<span class="lineNum">     998 </span>            : 
<span class="lineNum">     999 </span>            : template &lt;size_t N&gt;
<span class="lineNum">    1000 </span>            : PolymorphicAction&lt;
<span class="lineNum">    1001 </span>            :   internal::SetArgumentPointeeAction&lt;N, const wchar_t*, false&gt; &gt;
<span class="lineNum">    1002 </span>            : SetArgPointee(const wchar_t* p) {
<span class="lineNum">    1003 </span>            :   return MakePolymorphicAction(internal::SetArgumentPointeeAction&lt;
<span class="lineNum">    1004 </span>            :       N, const wchar_t*, false&gt;(p));
<span class="lineNum">    1005 </span>            : }
<span class="lineNum">    1006 </span>            : #endif
<span class="lineNum">    1007 </span>            : 
<span class="lineNum">    1008 </span>            : // The following version is DEPRECATED.
<span class="lineNum">    1009 </span>            : template &lt;size_t N, typename T&gt;
<span class="lineNum">    1010 </span>            : PolymorphicAction&lt;
<span class="lineNum">    1011 </span>            :   internal::SetArgumentPointeeAction&lt;
<span class="lineNum">    1012 </span>            :     N, T, internal::IsAProtocolMessage&lt;T&gt;::value&gt; &gt;
<span class="lineNum">    1013 </span>            : SetArgumentPointee(const T&amp; x) {
<span class="lineNum">    1014 </span>            :   return MakePolymorphicAction(internal::SetArgumentPointeeAction&lt;
<span class="lineNum">    1015 </span>            :       N, T, internal::IsAProtocolMessage&lt;T&gt;::value&gt;(x));
<span class="lineNum">    1016 </span>            : }
<span class="lineNum">    1017 </span>            : 
<span class="lineNum">    1018 </span>            : // Creates an action that sets a pointer referent to a given value.
<span class="lineNum">    1019 </span>            : template &lt;typename T1, typename T2&gt;
<span class="lineNum">    1020 </span>            : PolymorphicAction&lt;internal::AssignAction&lt;T1, T2&gt; &gt; Assign(T1* ptr, T2 val) {
<span class="lineNum">    1021 </span>            :   return MakePolymorphicAction(internal::AssignAction&lt;T1, T2&gt;(ptr, val));
<span class="lineNum">    1022 </span>            : }
<span class="lineNum">    1023 </span>            : 
<span class="lineNum">    1024 </span>            : #if !GTEST_OS_WINDOWS_MOBILE
<span class="lineNum">    1025 </span>            : 
<span class="lineNum">    1026 </span>            : // Creates an action that sets errno and returns the appropriate error.
<span class="lineNum">    1027 </span>            : template &lt;typename T&gt;
<span class="lineNum">    1028 </span>            : PolymorphicAction&lt;internal::SetErrnoAndReturnAction&lt;T&gt; &gt;
<span class="lineNum">    1029 </span>            : SetErrnoAndReturn(int errval, T result) {
<span class="lineNum">    1030 </span>            :   return MakePolymorphicAction(
<span class="lineNum">    1031 </span>            :       internal::SetErrnoAndReturnAction&lt;T&gt;(errval, result));
<span class="lineNum">    1032 </span>            : }
<span class="lineNum">    1033 </span>            : 
<span class="lineNum">    1034 </span>            : #endif  // !GTEST_OS_WINDOWS_MOBILE
<span class="lineNum">    1035 </span>            : 
<span class="lineNum">    1036 </span>            : // Various overloads for InvokeWithoutArgs().
<span class="lineNum">    1037 </span>            : 
<span class="lineNum">    1038 </span>            : // Creates an action that invokes 'function_impl' with no argument.
<span class="lineNum">    1039 </span>            : template &lt;typename FunctionImpl&gt;
<span class="lineNum">    1040 </span>            : PolymorphicAction&lt;internal::InvokeWithoutArgsAction&lt;FunctionImpl&gt; &gt;
<span class="lineNum">    1041 </span>            : InvokeWithoutArgs(FunctionImpl function_impl) {
<span class="lineNum">    1042 </span>            :   return MakePolymorphicAction(
<span class="lineNum">    1043 </span>            :       internal::InvokeWithoutArgsAction&lt;FunctionImpl&gt;(function_impl));
<span class="lineNum">    1044 </span>            : }
<span class="lineNum">    1045 </span>            : 
<span class="lineNum">    1046 </span>            : // Creates an action that invokes the given method on the given object
<span class="lineNum">    1047 </span>            : // with no argument.
<span class="lineNum">    1048 </span>            : template &lt;class Class, typename MethodPtr&gt;
<span class="lineNum">    1049 </span>            : PolymorphicAction&lt;internal::InvokeMethodWithoutArgsAction&lt;Class, MethodPtr&gt; &gt;
<span class="lineNum">    1050 </span>            : InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) {
<span class="lineNum">    1051 </span>            :   return MakePolymorphicAction(
<span class="lineNum">    1052 </span>            :       internal::InvokeMethodWithoutArgsAction&lt;Class, MethodPtr&gt;(
<span class="lineNum">    1053 </span>            :           obj_ptr, method_ptr));
<span class="lineNum">    1054 </span>            : }
<span class="lineNum">    1055 </span>            : 
<span class="lineNum">    1056 </span>            : // Creates an action that performs an_action and throws away its
<span class="lineNum">    1057 </span>            : // result.  In other words, it changes the return type of an_action to
<span class="lineNum">    1058 </span>            : // void.  an_action MUST NOT return void, or the code won't compile.
<span class="lineNum">    1059 </span>            : template &lt;typename A&gt;
<span class="lineNum">    1060 </span>            : inline internal::IgnoreResultAction&lt;A&gt; IgnoreResult(const A&amp; an_action) {
<span class="lineNum">    1061 </span>            :   return internal::IgnoreResultAction&lt;A&gt;(an_action);
<span class="lineNum">    1062 </span>            : }
<span class="lineNum">    1063 </span>            : 
<span class="lineNum">    1064 </span>            : // Creates a reference wrapper for the given L-value.  If necessary,
<span class="lineNum">    1065 </span>            : // you can explicitly specify the type of the reference.  For example,
<span class="lineNum">    1066 </span>            : // suppose 'derived' is an object of type Derived, ByRef(derived)
<span class="lineNum">    1067 </span>            : // would wrap a Derived&amp;.  If you want to wrap a const Base&amp; instead,
<span class="lineNum">    1068 </span>            : // where Base is a base class of Derived, just write:
<span class="lineNum">    1069 </span>            : //
<span class="lineNum">    1070 </span>            : //   ByRef&lt;const Base&gt;(derived)
<span class="lineNum">    1071 </span>            : template &lt;typename T&gt;
<span class="lineNum">    1072 </span>            : inline internal::ReferenceWrapper&lt;T&gt; ByRef(T&amp; l_value) {  // NOLINT
<span class="lineNum">    1073 </span>            :   return internal::ReferenceWrapper&lt;T&gt;(l_value);
<span class="lineNum">    1074 </span>            : }
<span class="lineNum">    1075 </span>            : 
<span class="lineNum">    1076 </span>            : }  // namespace testing
<span class="lineNum">    1077 </span>            : 
<span class="lineNum">    1078 </span>            : #endif  // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
